<?php
class tgyuanModel extends model{
	public $base;
	public $oc_where;
	public function __construct(&$base){
		parent::__construct($base);
		$this->base=$base;
		$this->table="tgyuan";
	}
	
	
	 
	
	public function getShopByIds($shopids,$fields=""){
		if(!empty($shopids)){
			$option['where']=" id in(".implode(",",$shopids).")";
			$fields && $option['fields']=$fields;
			$data=parent::select($option);
			if($data){
				$shoplist=array();
				foreach($data as $k=>$v){
					$shoplist[$v['id']]=$v;
				}
				return $shoplist;
			}
		}
		return false;
	}
	
	public function id_shop($option){
		$d=$this->select($option);
		if($d){
			foreach($d as $v){
				$data[$v['id']]=$v;
			}
			return $data;
		}
	}
	
	 
	public function addMoney($option){
		$shopid=$option['shopid'];
		$row=$this->selectRow("id=".$shopid);
		if(empty($row)) return false;
		$data=array();
		if(isset($option['money'])){
			$data['money']=$row['money']+$option['money'];
			
		}
		
		if(isset($option['income'])){
			$data['income']=$row['income']+$option['income'];
		}
		
		if(isset($option['balance'])){
			$data['balance']=$row['balance']+$option['balance'];
		}
		$this->update($data,"id=".$row['id']);
		 
		$logdata=array(
				"dateline"=>time(),
				"shopid"=>$shopid,
				"type_id"=>1,
				"siteid"=>SITEID,				 
		);
		
		
		if(isset($option['balance'])){
			$logdata['k']='balance';
			$logdata['money']=$option['balance'];
			$logdata['content']=str_replace("[money]",$option['balance'],$option['content']) ." 原来".$row['balance']."元，现在".$data['balance']."元";
			M("tgyuan_pay_log")->insert($logdata);
		}
		
		if(isset($option['income'])){
			$logdata['k']='income';
			$logdata['money']=$option['income'];
			$logdata['content']=str_replace("[money]",$option['income'],$option['content'])." 原来".$row['income']."元，现在".$data['income']."元";
			M("tgyuan_pay_log")->insert($logdata);
		}
		
		if(isset($option['money'])){
			$logdata['k']='money';
			$logdata['money']=$option['money'];
			$logdata['content']=str_replace("[money]",$option['money'],$option['content'])." 原来".$row['money']."元，现在".$data['money']."元";
			M("tgyuan_pay_log")->insert($logdata);
		}
		
	}
	
	
	
}

?>